#!/bin/bash
DATE=$(date +%Y%m%d)
DIR=/root/$1
hosts=(m1s1 m1s2)
JARFILE=$1.jar
if [ -z $1 ]
then
    echo "please input jar name"
exit 0
fi
for i in ${hosts[*]}
do
scp /var/lib/jenkins/workspace/gitee-project/target/$JARFILE root@$i:~/
ssh -tt $i <<EOF
echo "INFO:operate on ${i}"
if [ ! -d $DIR/backup ]
then
    mkdir -p $DIR/backup
fi
cd $DIR
ps -ef | grep $JARFILE | grep -v grep | awk '{print $2}' | xargs kill -9
mv $JARFILE backup/$JARFILE$DATE
mv -f ~/$JARFILE .
nohup java -jar $JARFILE &
exit
EOF
done
exit 0